---
id: filter
title: Filter Node
sidebar_label: Filter
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

![Filter Node Screenshot](./assets/filter-node.png)

## Overview

The Filter Node is used to filter an array based on a corresponding array of boolean values. The node takes in an array of any data type and an array of boolean values of the same length. It then filters the array, only including the elements where the corresponding boolean value is `true`.

This node is particularly useful when you want to filter an array based on some condition. For example, you could use a split (see [Splitting](../user-guide/splitting.md)) [Compare Node](./compare.mdx) to compare each element in an array to a value, and then use the Filter Node to filter the array based on the results of the comparison.

<Tabs
  defaultValue="inputs"
  values={[
    {label: 'Inputs', value: 'inputs'},
    {label: 'Outputs', value: 'outputs'},
    {label: 'Editor Settings', value: 'settings'},
  ]
}>

<TabItem value="inputs">

## Inputs

| Title   | Data Type   | Description                                                                         | Default Value | Notes                                                                                                                                             |
| ------- | ----------- | ----------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Array   | `any[]`     | The array to be filtered.                                                           | (required)    | The input will be coerced into an array if it is not an array.                                                                                    |
| Include | `boolean[]` | An array of boolean values indicating whether to include each element in the array. | (required)    | The input will be coerced into a boolean array if it is not a boolean array. The length of this array should match the length of the Array input. |

</TabItem>

<TabItem value="outputs">

## Outputs

| Title    | Data Type | Description                                                                                                             | Notes                                                                                                                                           |
| -------- | --------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Filtered | `any[]`   | The filtered array, containing only the elements where the corresponding boolean value in the Include input was `true`. | The output will be an array of the same data type as the Array input. If the Array input is not an array, the output will be an array of `any`. |

</TabItem>

<TabItem value="settings">

## Editor Settings

This node has no configurable editor settings.

</TabItem>

</Tabs>

## Example 1: Filter an array of numbers

1. Create an [Array Node](./array.mdx) and set the values to `[1, 2, 3, 4, 5]`.
2. Create another Array Node and set the values to `[true, false, true, false, true]`.
3. Create a Filter Node and connect the first Array Node to the `Array` input and the second Array Node to the `Include` input.
4. Run the graph. The `Filtered` output of the Filter Node should be `[1, 3, 5]`.

![Filter Node Example 1](./assets/filter-node-example-01.png)

## Example 2: Filter an array based on a condition

1. Create an [Array Node](./array.mdx) and set the values to `[1, 2, 3, 4, 5]`.
2. Create a [Compare Node](./compare.mdx) and set the comparison to `>`. Enable splitting on the Compare node.
3. Create a [Number Node](./number.mdx) and set the value to `3`.
4. Connect the Array Node to the `A` input of the Compare Node, and connect the Number Node to the `B` input of the Compare Node.
5. Create a Filter Node and connect the Compare Node to the `Array` input and the `Result` output of the Compare Node to the `Include` input.
6. Run the graph. The `Filtered` output of the Filter Node should be `[4, 5]`.

![Filter Node Example 2](./assets/filter-node-example-02.png)

## Error Handling

The Filter Node will error if the `Array` or `Include` inputs are not provided, or if the lengths of the arrays do not match.

## FAQ

**Q: What happens if the lengths of the Array and Include inputs do not match?**

A: The Filter Node will error. The lengths of the Array and Include inputs should always match.

**Q: Can I use the Filter Node to filter an array of objects?**

A: Yes, you can use the Filter Node to filter an array of any data type, including objects. Just make sure to provide an array of boolean values indicating whether to include each object in the filtered array.

## See Also

- [Array Node](./array.mdx)
- [Compare Node](./compare.mdx)
- [Number Node](./number.mdx)
- [Splitting](../user-guide/splitting.md)
- [Extract Object Path Node](./extract-object-path.mdx)
- [Evaluate Node](./evaluate.mdx)
- [Coalesce Node](./coalesce.mdx)
- [Join Node](./join.mdx)
